package com.web.base.user.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.blue.jdbc.Page;
import com.web.base.user.message.UserLoginLogRequest;
import com.web.base.user.message.UserLoginLogResponse;
import com.web.base.user.model.UserLoginLog;

/**
 * 登录日志转换器
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 2017年04月16日
 */
public class UserLoginLogConvertor
{
	private UserLoginLogConvertor()
	{
	}
	
	public static UserLoginLog toUserLoginLog(UserLoginLogRequest request)
	{
		if (request == null)
			return null;
		
		UserLoginLog userLoginLog = new UserLoginLog();
		userLoginLog.setId(request.getId());
		userLoginLog.setUserId(request.getUserId());
		userLoginLog.setDescp(request.getDescp());
		userLoginLog.setResult(request.getResult());
		userLoginLog.setLoginTime(request.getLoginTime());
		userLoginLog.setIp(request.getIp());
		userLoginLog.setAddress(request.getAddress());
		return userLoginLog;
	}
	
	public static UserLoginLogResponse toResponse(UserLoginLog userLoginLog)
	{
		if (userLoginLog == null)
			return null;
		
		UserLoginLogResponse response = new UserLoginLogResponse();
		response.setId(userLoginLog.getId());
		response.setUserId(userLoginLog.getUserId());
		response.setDescp(userLoginLog.getDescp());
		response.setResult(userLoginLog.getResult());
		response.setLoginTime(userLoginLog.getLoginTime());
		response.setIp(userLoginLog.getIp());
		response.setAddress(userLoginLog.getAddress());

		response.setAppName(userLoginLog.getAppName());
		return response;
	}
	
	public static List<UserLoginLogResponse> toResponse(List<UserLoginLog> list)
	{
		List<UserLoginLogResponse> responseList = new ArrayList<>();
		if (list == null || list.isEmpty())
			return responseList;
		
		for (UserLoginLog userLoginLog : list)
		{
			responseList.add(toResponse(userLoginLog));
		}
		return responseList;
	}
	
	public static Map<Integer, UserLoginLogResponse> toResponse(Map<Integer, UserLoginLog> map)
	{
		Map<Integer, UserLoginLogResponse> responseMap = new HashMap<>();
		if (map == null || map.isEmpty())
			return responseMap;
		
		for (Map.Entry<Integer, UserLoginLog> entry : map.entrySet())
		{
			responseMap.put(entry.getKey(), toResponse(entry.getValue()));
		}
		return responseMap;
	}
	
	public static Page<UserLoginLogResponse> toResponse(Page<UserLoginLog> page)
	{
		if (page == null)
			return null;
		
		Page<UserLoginLogResponse> responsePage = new Page<>();
		responsePage.setCurPage(page.getCurPage());
		responsePage.setRows(page.getRows());
		responsePage.setSize(page.getSize());
		responsePage.setStartRowNo(page.getStartRowNo());
		responsePage.setTotalPage(page.getTotalPage());
		responsePage.setObjectList(toResponse(page.getObjectList()));
		return responsePage;
	}
	
}
